package com.ruoyi.web.ydz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.ydz.domain.Clinical;
import com.ruoyi.web.ydz.service.IClinicalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 临床招募Controller
 * 
 * @author DRX
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/ydz/clinical")
public class ClinicalController extends BaseController
{
    @Autowired
    private IClinicalService clinicalService;

    /**
     * 查询临床招募列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:clinical:list')")
    @GetMapping("/list")
    public TableDataInfo list(Clinical clinical)
    {
        startPage();
        List<Clinical> list = clinicalService.selectClinicalList(clinical);
        return getDataTable(list);
    }

    /**
     * 查询临床招募列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:clinical:list')")
    @PostMapping("/getClinicalList")
    public TableDataInfo getClinicalList(@RequestBody Clinical clinical)
    {
        startPage();
        List<Clinical> list = clinicalService.getClinicalList(clinical);
        return getDataTable(list);
    }

    /**
     * 导出临床招募列表
     */
    @PreAuthorize("@ss.hasPermi('ydz:clinical:export')")
    @Log(title = "临床招募", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Clinical clinical)
    {
        List<Clinical> list = clinicalService.selectClinicalList(clinical);
        ExcelUtil<Clinical> util = new ExcelUtil<Clinical>(Clinical.class);
        util.exportExcel(response, list, "临床招募数据");
    }

    /**
     * 获取临床招募详细信息
     */
    @PreAuthorize("@ss.hasPermi('ydz:clinical:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(clinicalService.selectClinicalById(id));
    }

    /**
     * 新增临床招募
     */
    @PreAuthorize("@ss.hasPermi('ydz:clinical:add')")
    @Log(title = "临床招募", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Clinical clinical)
    {
        return toAjax(clinicalService.insertClinical(clinical));
    }

    /**
     * 修改临床招募
     */
    @PreAuthorize("@ss.hasPermi('ydz:clinical:edit')")
    @Log(title = "临床招募", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Clinical clinical)
    {
        return toAjax(clinicalService.updateClinical(clinical));
    }

    /**
     * 删除临床招募
     */
    @PreAuthorize("@ss.hasPermi('ydz:clinical:remove')")
    @Log(title = "临床招募", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(clinicalService.deleteClinicalByIds(ids));
    }
}
